<?php


namespace App\Dao;


use App\Model\ConfigBanner;

class ConfigBannerDao extends AbstractDao
{



    public function where(array $where): \Hyperf\Database\Model\Builder
    {
        $builder = ConfigBanner::query();

        foreach ($where as $field => $value) {
            switch ($field) {
                case 'ids':
                    if (!empty($value)) {
                        $builder->whereIn('id', $value);
                    }
                    break;
                default:
                    $builder->where($field, $value);
                    if (is_array($value)) {
                        $builder->where($field, $value[0], $value[1]);
                    } else {
                        $builder->where($field, $value);
                    }
            }
        }

        return $builder;
    }

    /**
     * 根据id更新数据
     * @param array $where
     * @param array $data
     * @return int
     */
    public function updateData(array $where,array $data)
    {
       return ConfigBanner::query()
           ->where('cooperative_id',$where['cooperative_id'])
           ->orWhereIn('id',$where['ids'])->update($data);
    }
}

